import * as api from "../../api/mine";
import * as data from "../../api/data";

var dayjs = require('dayjs');

Page({
    data: {
        totalJson:{
            increasePerson: 0,
            increaseSaleCount: 0,
            saleAmount: 0,
            saleCount: 0,
            saleOrder: 0,
            salePerson: 0
        },
        fundSite:[],
        brand:[],
        countDate:"",
        dataType:""
    },
    async onLoad(){
        this.set_init_date("DAY");
        this.get_data_list();
    },
    set_init_date(dataType){
        let start, end;
        if( dataType == 'MONTH'){
            start = dayjs().startOf("month").format("YYYY-MM-DD");
            end = dayjs().format("YYYY-MM-DD")
        }
        else if(dataType == 'DAY'){
            start = dayjs().format("YYYY-MM-DD");
            end = dayjs().format("YYYY-MM-DD")
        }
        this.setData({
            countDate:start+','+end,
            dataType:dataType
        })
    },
    async get_data_list(){

        let totalJson = await data.getDataTotal({
            dataType:this.data.dataType,
            countDate:this.data.countDate
        });

        let fundSite = await data.getRankForFundSite({
            dataType:this.data.dataType,
            countDate:this.data.countDate,
            limitNum:5
        });

        let brand = await data.getRankForBrand({
            dataType:this.data.dataType,
            countDate:this.data.countDate,
            limitNum:5
        });

        this.setData({
            totalJson:totalJson,
            fundSite:fundSite,
            brand:brand
        })

    },
    change_header_data(e){
        this.setData({
            dataType:e.detail.dataType,
            countDate:e.detail.countDate
        })
        this.get_data_list();
    },
    handle_to_fund(){
        let dataType = this.data.dataType;
        let countDate = this.data.countDate
        wx.navigateTo({
            url: '/pages/data-fund/data-fund?dataType='+dataType+"&countDate="+countDate
        });
    },
    handle_to_brand(){
        let dataType = this.data.dataType;
        let countDate = this.data.countDate
        wx.navigateTo({
            url: '/pages/data-brand/data-brand?dataType='+dataType+"&countDate="+countDate
        });
    }
    
})


